/*
 * @Author: shanghongyun 2879455630@qq.com
 * @Date: 2025-05-30 13:17:38
 * @LastEditors: shanghongyun 2879455630@qq.com
 * @LastEditTime: 2025-06-11 17:22:45
 * @FilePath: \A05\Dev\EPWM.c
 * @Description: EPWM配置文件
 */

#include "dev.h"


/**
 * @description: epwm初始化
 * @return {*}
 */
void epwm_config(void){
    /* 设置PA0-5管脚复用配置*/
    SYS->GPA_MFP = (SYS->GPA_MFP & (~SYS_GPA_MFP_PA3MFP_Msk));
    SYS->GPA_MFP |= SYS_GPA_MFP_PA3_EPWM_CH3;
    SYS->GPA_MFP = (SYS->GPA_MFP & (~SYS_GPA_MFP_PA4MFP_Msk));
    SYS->GPA_MFP |= SYS_GPA_MFP_PA4_EPWM_CH4;
    /* 设置PA0-5为输出模式 */
    GPIO_SetMode(PA, BIT3 | BIT4, GPIO_MODE_OUTPUT);

    /*PWM计数器自动清零 调试模式关闭 自动装载模式*/
    EPWM->CTL |= EPWM_CTL_CNTCLR_Msk | EPWM_CTL_DBGTRIOFF_Msk | EPWM_CTL_CNTMODE_Msk;
    /*独立模式*/
    EPWM_DISABLE_COMPLEMENTARY_MODE(EPWM);
    /*不分频*/
    EPWM->CLKDIV = 0x00;
    /*计数器向上计数*/
    // EPWM->CNT |= EPWM_CNT_CNTDIR_Msk; 

    /*PWM频率设置*/
    EPWM->PERIOD = EPWM_PERIOD;

    /*设置占空比*/
    EPWM_SET_CMR(EPWM, 3, EPWM_DUTY(0));
    EPWM_SET_CMR(EPWM, 4, EPWM_DUTY(0));

    EPWM_Start(EPWM, 0x18);  /*开启CH3和CH4*/

}



